#ifndef __GfxDriver_WGL_WGLGfxDriver_h__
#define __GfxDriver_WGL_WGLGfxDriver_h__

#include "GfxDriver/GfxDriver.h"
#include "GfxDriver/WGL/GLInclude.h"

namespace Orca {

	//--------------------------------------------------------------------------
	class WGLGfxDriver : public GfxDriver {

	public:
		WGLGfxDriver();
		virtual ~WGLGfxDriver();

		virtual bool startup();
		virtual void shutdown();

		virtual void step(float dt);

		virtual void resetErrors();

		virtual void clearFrameBuf(const vec4 &value);
		virtual void clearDepthBuf(float value);
		virtual void clearStencilBuf(uint32 value);
		virtual void clearAllBufs(const vec4 &clr, float depth, uint32 stencil);

		virtual VertexProgram* createVertexProgram(const uint8* data);
		virtual FragmentProgram* createFragmentProgram(const uint8* data);
		virtual Shader* createShader(VertexProgram *vp, FragmentProgram *fp);

		virtual Texture2d* create2DTexture(uint32 w, uint32 h, PixelFormat format);
		virtual TextureCube* createCubeTexture(uint32 size, PixelFormat format);
		virtual TextureRendered* createRenderedTexture(uint32 w, uint32 h, PixelFormat format);
		
		virtual VertexBuffer* createVertexBuffer(uint32 sizeInBytes, bool staticUsage);
		virtual VertexInput* createVertexInput();
		virtual IndexBuffer* createIndexBuffer(uint32 sizeInBytes, bool staticUsage);

		virtual RenderTarget* createRenderTarget();
		virtual DepthBuffer* createDepthBuffer(
			 uint32 width
			,uint32 height
			,uint32 depthBits
			,uint32 stencilBits);

		virtual bool bindRenderTarget(RenderTarget *renderTarget);

		virtual bool bindTexture(uint32 channel, Texture *tex);
		
		virtual void setViewport(uint32 x, uint32 y, uint32 width, uint32 height);
		virtual bool beginRender();
		virtual void endRender();

		virtual bool beginDrawing(VertexInput *vertexInput);
		virtual void draw(PrimitiveType primType, uint32 startVertex, uint32 primCnt);
		virtual void drawIndexed(PrimitiveType primType, uint32 startIndex, uint32 primCnt);
		virtual void endDrawing();

		void setCurrentGLIndexType(GLenum indexType);

		virtual void setCullMode(CullMode cullMode);

		virtual void setDepthTestEnable(bool enable);
		virtual void setDepthTestFunc(CmpFunc cmp);
		virtual void setDepthWriteEnable(bool enable);

		virtual void setAlphaBlendEnable(bool enable);
		virtual void setSeperatedAlphaBlendEnable(bool enable);
		virtual void setAlphaBlendColorFactor(BlendFactor srcFactor, BlendFactor destFactor);
		virtual void setAlphaBlendAlphaFactor(BlendFactor srcFactor, BlendFactor destFactor);

		virtual void setAlphaTestEnable(bool enable);
		virtual void setAlphaTestFunc(CmpFunc cmp, float refValue);

		virtual void setWorldTransform(const mtx44 &mtx);
		virtual void setViewTransform(const mtx44 &mtx);
		virtual void setProjTransform(const mtx44 &mtx);

	private:
		GLenum mCurrIndexType;
		mtx44 mWorldMtx;
		mtx44 mViewMtx;
		mtx44 mProjMtx;

		GLenum mSrcClrBlend, mDestClrBlend;

		void _updateGLModelViewMtx();
		void _updateGLProjMtx();
	};

}

#endif	// __GfxDriver_WGL_WGLGfxDriver_h__